package one_day;

import java.util.Scanner;

/**
 * 编写程序，对输入的年、月、日，给出该天是该年的第多少天？
 */
public class HowDays {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /**
         * 平年每月的天数
         */
        int[] days = new int[]{31, 30, 31, 28, 31, 30, 31, 31, 30, 31, 30, 31};
        System.out.println("请输入一个日期，格式为****年**月**日：");
        String date = sc.next();
        int year = Integer.parseInt(date.substring(0, 4));
        int mouth = Integer.parseInt(date.substring(5, 7));
        int day = Integer.parseInt(date.substring(8, 10));
        /**
         * 判断该年是否是闰年
         */
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            days[3] = 29;
        }
        int res = 0;
        for (int i = 0; i < mouth - 1; i++) {
            res += days[i];
        }
        res += day;
        System.out.println(date + "，是该年的第" + res + "天。");
    }
}
